<?php

session_start();
//require_once 'MyDB.php';
require_once './src/MyDBi.php';
$db = new MysqliDb();
//print_r($db);
//$con = new MyDB();
//$query = $con->selectFrom("usuarios", $columns = null, $where = array('Usuario' => $_REQUEST['usr'], 'Password' => $_REQUEST['pswd']), $like = false, $orderby = null, $direction = "DESC", $limit = null, $offset = null);
//$num = $query["num"];

$txtUsr = $_REQUEST['usr'];
$txtPwd = $_REQUEST['pswd'];
$db->where('Usuario', $txtUsr);
$db->where('Password', $txtPwd);
$results = $db->get('usuarios');
//print_r($db);
//print_r($results);
//if ($num > 0) {
if ($db->count > 0) {
//    $result = $query["result"];
    foreach ($results as $row) {
        //echo $row['IdUsuario'] . " " . $row['Nombre'];
        $_SESSION['ha_usr'] = $row['IdUsuario'];
        $_SESSION['ha_rol'] = $row['IdRol'];
    }

    $db->where('IdMovimientoCierre', '-1');
    $results = $db->get('cajas');
    if ($db->count > 0) {
        foreach ($results as $row) {
            $_SESSION['ha_usuariocaja'] = $row['IdUsuario'];
            $_SESSION['ha_idcaja'] = $row['IdCaja'];
        }

        ini_set("log_errors", 1);
        ini_set("error_log", "./php-error.log");
        error_log("Hello, errors!");
    } else {
        $_SESSION['ha_idcaja'] = '-1';
    }
    header("Location: ./content.php");
} else {
    header("Location: ./index.php");
}
?>
